package cn.edu.ctbu.labtest.controller;

import cn.edu.ctbu.labtest.domain.Student;
import cn.edu.ctbu.labtest.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@Slf4j
public class SelfController {
    @Autowired
    StudentService studentService;

    @RequestMapping("/student/slist")
    public String self(HttpServletRequest httprequest, Model model, String username, String password) {
        HttpSession session = httprequest.getSession();
        if(session.getAttribute("userid")==null){
            //未登录，需要去登录
            return "redirect:/login/user";
        }
        log.info("name:{}",username);
        List<Student> student = studentService.findByNameAndPassword(username, password);
        model.addAttribute("user", student);
        return "/student/slist";
    }


//    @RequestMapping("/student/findByName")
//    public List<Student> findByName(String name){
//        return studentService.findByName(name);
//    }

//    @RequestMapping("/student/self")
//    public String self(HttpServletRequest httprequest, Model model, String username) {
//        HttpSession session = httprequest.getSession();
//        if (session.getAttribute("userid") == null) {
//            //未登录，需要去登录
//            return "redirect:/login/user";
//        }
//        log.info("name:{}", username);
//        List<Student> students = studentService.findByName(username);
//        model.addAttribute("selfStudent", students);
//        return "/student/self";
//    }

}


